package ynu.lcy.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.modelmapper.ModelMapper;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import ynu.lcy.dto.business.AddOrderTypeRequestDTO;
import ynu.lcy.elememicroservicecommon.utils.BaseResponse;
import ynu.lcy.elememicroservicecommon.utils.ResultUtils;

import ynu.lcy.entity.OrderType;
import ynu.lcy.service.OrderTypeService;
import ynu.lcy.vo.TypeVO;

import javax.annotation.Resource;
import java.util.List;

@RestController
@CrossOrigin
@Api(tags="类型")
@RequestMapping("/orderType")
public class BusinessTypeController {

    @Resource
    private ModelMapper mapper;

    @Resource
    private OrderTypeService orderTypeService;

    /**
     * 获取所有点餐类型
     * @param
     * @return BaseResponse<List<TypeVO>>
     * */
    @GetMapping("/list")
    @ApiOperation("获取所有点餐类型")
    public BaseResponse<List<TypeVO>> list(){
        List<TypeVO> vos =orderTypeService.list().stream().map(o -> mapper.map(o, TypeVO.class)).toList();
        return ResultUtils.success(vos);
    }

    /**
     * 添加标签
     * */
    @PostMapping("/admin/add")
    @ApiOperation("添加标签")
    public BaseResponse<TypeVO> add(@ApiParam("请求实体") AddOrderTypeRequestDTO dto){
        OrderType orderType = orderTypeService.add(dto);
        return ResultUtils.success(mapper.map(orderType, TypeVO.class));
    }
}
